<?php
class RecommendationsModel extends BaseModel implements Model {
    function __construct() {
        parent::__construct("recommendations", "id");
        $this->addField("id", Model::TYPE_INT, Model::MOD_PRIMARY);
        $this->addField("companyname", Model::TYPE_VARCHAR);
        $this->addField("service_type", Model::TYPE_VARCHAR);
        $this->addField("service_description", Model::TYPE_TEXT);
    }

    public function renderAlias($record) {
        $result = $record;
        return $result;
    }

    public function acceptRecommendation($id) {
        $query = "SELECT * FROM recommendations WHERE id=$id";
        $res = Database::executeQuery($query);
        $data = Database::getDatafromresource($res);
        $query = QueryHelper::insertInto("companies", array(
            companyname => $data[0]['companyname'],
        ));
        Database::executeQuery($query);
        $id = Database::getInsertedId();
        $query = QueryHelper::insertInto("recommended_services", array(
            company_id => $id,
            service_type => $data[0]['service_type'],
            service_description => $data[0]['service_description'],
        ));
        Database::executeQuery($query);
    }

    public function isAuthorized($operation, $subject = "") {
        return true;
    }

    public function modifyDatabaseInput($data) {
        return $data;
    }
}

?>
